export function getRandomStr(val, fixed) { // 获取一个随机 0 or 1
    return parseInt(Math.random().toString().charAt(11)) >= 5 ? '1' : '0';
}

export function getRandomStr3() { // 获取一个随机 0 or 1 or -1
    var num = parseInt(Math.random().toString().charAt(11));
    for (var i = 0; i < 10;) {
        if (num === 0) {
            num = parseInt(Math.random().toString().charAt(11));
        } else {
            break;
        }
    }
    if (num <= 3) {
        return '0';
    } else if (num <= 6) {
        return '1';
    } else {
        return '-1';
    }
}

export function getRandomRange(max) {
    var maxList = [];
    for (var i = 0; i < max; i++) {
        maxList.push(i)
    }
    for (var i = 0; i < 10;) {
        if (maxList.length % 2 === 0) {
            if (getRandomStr() === '1') {
                maxList = maxList.slice(maxList.length / 2, maxList.length);
            } else {
                maxList = maxList.slice(0, maxList.length / 2)
            }
        } else {
            let str3 = getRandomStr3();
            if (str3 === '-1') {
                maxList = maxList.slice(0, maxList.length / 3);
            } else if (str3 === '0') {
                maxList = maxList.slice(maxList.length / 3, (maxList.length / 3) * 2)
            } else {
                maxList = maxList.slice((maxList.length / 3) * 2, maxList.length)
            }
        }
        if (maxList.length === 1) {
            return maxList[0];
        }
    }
}